﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NotebookPortal
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection oConnection = new SqlConnection();
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataTable dt = new DataTable();

            oConnection.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["CNS"].ToString();
            oConnection.Open();

            oCommand.Connection = oConnection;
            oCommand.CommandText = "SELECT * FROM USERS WHERE UserID=@UserID and UserPassword=@UserPassword";
            oCommand.Parameters.Add(new SqlParameter("@UserID", txtUserID.Text));
            oCommand.Parameters.Add(new SqlParameter("@UserPassword", txtPassword.Text));

            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(dt);

            oConnection.Close();

            if (dt.Rows.Count == 1)
            {
                Session.Clear();
                Session.Add("ActiveUserID", txtUserID.Text);

                Response.Redirect("default.aspx");
                
            }
        }
    }
}